package atlantik.peer;

import atlantik.game.Atlantik;
import atlantik.game.Estate;
import atlantik.ui.EstateView;

public class EstatePeer extends AbstractPeer<Estate, EstateView> {

	public EstatePeer(Atlantik client, Estate item) {
		super(client, item, new EstateView(client, item));
	}

	public void add(TokenPeer token) {
		EstateView view = getComponent();
		view.add(token.getComponent());
		view.repaint();
	}

	public void remove(TokenPeer token) {
		EstateView view = getComponent();
		view.remove(token.getComponent());
		view.repaint();
	}

	public void updated(Estate item) {
		super.updated(item);
		StringBuffer toolTip = new StringBuffer();
		if (item.getOwner() != null)
			toolTip.append(String.format("Owner: <b>%s</b><br>", item
					.getOwner().getName()));
		if (item.getPrice() != 0)
			toolTip.append(String.format("Price: %d<br>", item.getPrice()));
		if (item.getMortgagePrice() != 0)
			toolTip.append(String.format(
					"Mortgage Price: %d<br>Unmortgage Price: %d<br>", item
							.getMortgagePrice(), item.getUnmortgagePrice()));

		getComponent().setToolTipText(String.format("<html><b>%s</b> (%d)<br>%s</html>", item
				.getName(), item.getId(), toolTip.toString()));
	}

}
